{include file="public/header" /}
</head>
<body>
<div class="layui-btn-container" style="padding: 20px;">
    {gt name="userListCount" value="1"}
    <button class="layui-btn layui-btn-radius {empty name="substations"}layui-btn-disabled{/empty}" data-id="0">全部</button>
    {/gt}
    {notempty name="userList"}
    {volist name="userList" id="vo"}
    <button class="layui-btn layui-btn-radius {if condition="$substations eq $vo['substation_id']"}layui-btn-disabled{/if}" data-id="{$vo.substation_id}">{$vo.substation_name}</button>
    {/volist}
    {/notempty}
</div>
</body>
<script>
    $(function () {
        $(".layui-btn").click(function () {
            if(!$(this).is(".layui-btn-disabled")){
                var id = $(this).attr("data-id");
                var QQIndex = layer.msg('请求中...', {
                        icon: 16
                        ,shade: 0.01
                        ,time:0
                });
                $.post("{:url('Home/setSubstation')}", {"substation_id": id}, function (data, status) {
                    layer.close(QQIndex);
                    layer.msg(data.msg,{time:2000,success:function () {
                        if(data.code == 0) {
                            parent.layer.msg('切换中...', {
                                icon: 16
                                ,shade: 0.01
                                ,time:0
                            });
                            parent.window.location.href = "{:url('Home/index')}"; //跳转
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }
                    }});
                });
            }
        });
    })
</script>
</html>